/*
 *   method.c
 *
 */
#include <stdio.h>
#include <stdlib.h>
#include <time.h>
#include <sys/time.h>

#include "frcomm.h"
#include "frmem.h"
#include "frstr.h"
#include "frlist.h"

#include "conntrack.h"
#include "module.h"

int l7default_init(int i_l7_proto, const char *p_module_name, unsigned int ui_mempool_max)
{
    char *p_data1=NULL;

    frdbg("%s run\n", p_module_name);

    //p_data1 = frmalloc(10);
    //frfree(p_data1);

    return 0;
}

int l7default_destroy(void)
{
    frdbg("l7default_destroy run\n");
    return 0;
}

int l7default_l7_is(Conntrack *p_st_conn, Analyze_data_in *p_st_data_in)
{
    struct timeval tpstart;
    int i_ret = APM_L7_IS_NO;
    
    frdbg("check protocol\n");
    
    gettimeofday(&tpstart,NULL);
    srand(tpstart.tv_usec);
    
//    switch( rand() %3 )
//    {
//        case 0:
//            i_ret = APM_L7_IS_NO;
//            break;
//        case 1:
//            i_ret = APM_L7_IS_YES;
//            break;
//        default:
            i_ret = APM_L7_IS_UNKNOWN;
//            break;
//    }
    
    return i_ret;
}

int l7default_l7_analyze(Conntrack *p_st_conn
                    , Analyze_data_in *p_st_input
                    , Frhash_header  *p_st_hash_report   //保存Frreport_data
                    , Frlist_header  *p_st_list_output   //保存Analyz_data_out
                    )
{
    struct timeval tpstart;
    int i_ret = APM_L7_IS_NO;
    
    gettimeofday(&tpstart,NULL);
    srand(tpstart.tv_usec);

    switch( rand() %9 )
    {
        case 1:
            i_ret = APM_L7_ANALYZE_FAIL;
            break;
        case 2:
            i_ret = APM_L7_ANALYZE_REDETECT;
            break;
        case 3:
            i_ret = APM_L7_ANALYZE_TODO;
            break;
        case 4:
            i_ret = APM_L7_ANALYZE_SET_REQ(APM_L7_ANALYZE_SUCC);
            break;
        case 5:
            i_ret = APM_L7_ANALYZE_SET_RESP(APM_L7_ANALYZE_SUCC);
            break;
        case 6:
            i_ret = APM_L7_ANALYZE_SUCC;
            break;
        case 7:
            i_ret = APM_L7_ANALYZE_STOP;
            break;
        default:
            i_ret = APM_L7_ANALYZE_SUCC;
            break;
    }
    
    //frdbg("run ret=%d\n", i_ret);
    return i_ret;
}


int l7default_session_destory(void *p_session_private)
{
    frdbg("l7default_session_destory run\n");
    return 0;
}


